<?php
/**
 * Created by PhpStorm.
 * User: 图图
 * Date: 2021-6-8
 * Time: 16:29
 */

namespace app\web\controller;
use app\common\controller\Api;
use app\common\model\Factor;
use app\common\model\Fenorder;
use app\web\controller\Express;
use think\Db;
use app\common\model\ReportConfig as ReportConfigM;

/**
 * 技师汇总报表配置
 * @package app\index\controller
 */
class ReportConfig extends Auth
{
    public $noNeedLogin = [];

    /**
     * 获取技师报表配置
     */
    public function getReportConfig(){
        $data  = ReportConfigM::get_config();
        $this->result('查询成功', $data, 200);
    }

    /**
     * 保存技师报表配置
     */
    public function saveReportConfig(){
        if($this->request->isPost()){
            $getData = $this->request->post();
            $getData['store_id'] = $this->userInfo['store_id'];
            $data  = ReportConfigM::save_config($getData);
            if($data == true){
                $this->result('保存成功', '', 200);
            }
            $this->result('保存失败', '', 204);
        }

    }


    /**
     * 删除技师报表配置
     */
    public function delReportConfig(){
        if($this->request->isPost()){
            $getData = $this->request->post();
            if(empty($getData['report_id'])){
                $this->result('缺少参数', '', 204);
            }
            $data  = ReportConfigM::del_config($getData);
            if($data == true){
                $this->result('删除成功', '', 200);
            }
            $this->result('删除失败', '', 204);
        }

    }

    /**
     *获取技师报表二配置详情
     */
    public function getEngineerReportDetail(){
        if($this->request->isPost()){
            $getData = $this->request->post();
            if(empty($getData['report_id'])){
                $this->result('缺少参数', '', 204);
            }else{
                $data = Db::name('qt_report')
                    ->where(['store_id'=>$this->userInfo['store_id'],'id'=>$getData['report_id']])->find();
            }
            $data['list'] = Db::name('qt_report_item')->where(['report_id'=>$data['id']])->select();
            $this->result('查询成功', $data, 200);
        }else{
            $this->result('无效的请求方式', '', 204);
        }


    }

    /**
     *获取技师报表二配置列表
     */
    public function getEngineerReportList(){
        if($this->request->isPost()){
            $data = Db::name('qt_report')->field('id as report_id,temp_name')->where(['store_id'=>$this->userInfo['store_id']])->select();
            $this->result('查询成功', $data, 200);
        }else{
            $this->result('无效的请求方式', '', 204);
        }


    }


}
